from django.template import Library
from django.template.context import Context, RequestContext, ContextPopException
from django.template.loader import get_template, select_template
from django.conf import settings
from xadmin.admin import XModelAdminButton
register = Library()


def xadmin_media_url():
    """
    Returns the string contained in the setting ADMIN_MEDIA_PREFIX.
    """
    return settings.XADMIN_MEDIA_URL
xadmin_media_url = register.simple_tag(xadmin_media_url)

def xadmin_theme():
    """
    Returns the string contained in the setting ADMIN_MEDIA_PREFIX.
    """    
    from xadmin.settings import THEME
    return THEME
xadmin_theme = register.simple_tag(xadmin_theme)


def xadmin_button(label, link, icon=None):
    return str (XModelAdminButton( label, link, icon ) )
#    
#    ctx =  {'label': label, 
#            'url' : link,
#            'icon' : "ui-icon " + icon if icon else ""
#            }
#    t = get_template('xadmin/inlines/ui_button.html')
#    return t.render(Context(ctx))


xadmin_button = register.simple_tag(xadmin_button)